﻿using System;
using System.Collections.Generic;
using AwesomeEnginePC.Physics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace AwesomeEnginePC.Graphics.TwoDimensional.Sprites
{
    public class SpriteRotator //: Base2DObject
    {
        //private int _currentImageIndex;
        //private List<BaseSprite> _imageList;
        //private bool _isRunning;
        //private TimeSpan _previousShowingImageTime;
        //private TimeSpan _timeBetweenSprites;
        //private int frameHeight;
        //private int frameWidth;
        //public SpriteRotator(ContentManager CM, int width, int height)
        //    : base(CM)
        //{
        //    _imageList = new List<BaseSprite>();

        //    _currentImageIndex = 0;
        //    frameWidth = width;
        //    frameHeight = height;

        //    _isRunning = false;
        //}

        //public Vector<int> CenterPoint
        //{
        //    get { return new Vector<int>(Width / 2, Height / 2); }
        //}

        //public int CurrentImageIndex
        //{
        //    get { return _currentImageIndex; }
        //}

        //public override int RawHeight { get { return frameWidth; } }

        //public override int RawWidth { get { return frameWidth; } }

        ///// <summary>
        ///// Gets or sets if the rotator will loop when it is complete.
        ///// </summary>
        //public bool WillLoop { get; set; }
        //public void AddImage(string AssetName)
        //{
        //    BaseSprite imageToAdd = new BaseSprite(CM, AssetName);
        //    imageToAdd.LoadFromSettings(this.GetBase2DObjectSettings());
        //    _imageList.Add(imageToAdd);
        //}

        //protected override void DrawInner(GameTime gameTime, SpriteBatch SB)
        //{
        //    _imageList[_currentImageIndex].LoadFromSettings(this.GetBase2DObjectSettings(), SpriteEffects.None, null);
        //    _imageList[_currentImageIndex].Height = this.Height;
        //    _imageList[_currentImageIndex].Width = this.Width;
        //    _imageList[_currentImageIndex].Origin = ConvertGlobalOriginToSpriteOrigin(_currentImageIndex);

        //    _imageList[_currentImageIndex].Draw(gameTime, SB);
        //}

        ////public void Play(ImageRotatorTransitionType transitionType, TimeSpan timeBetweenSprites, bool willLoop)
        //public void Play(TimeSpan timeBetweenSprites, bool willLoop)
        //{
        //    WillLoop = willLoop;

        //    //TransitionType = transitionType;
        //    _timeBetweenSprites = timeBetweenSprites;
        //    _isRunning = true;

        //    //status = ImageRotatorStatus.ShowingImage;
        //}

        //public void Stop()
        //{
        //    _isRunning = false;

        //    //status = ImageRotatorStatus.Stopped;
        //}

        //public override void Update(GameTime gameTime)
        //{
        //    if (_previousShowingImageTime == null)
        //    {
        //        _previousShowingImageTime = new TimeSpan(gameTime.TotalGameTime.Ticks);
        //    }

        //    if (_isRunning)
        //    {
        //        if (gameTime.TotalGameTime - _previousShowingImageTime >= _timeBetweenSprites)
        //        {
        //            _previousShowingImageTime = new TimeSpan(gameTime.TotalGameTime.Ticks);

        //            //time to go to next image
        //            GoToNextImage();
        //        }
        //    }
        //}

        //private Vector<int> ConvertGlobalOriginToSpriteOrigin(int imageIndex)
        //{
        //    double globOrgPercX = this.Origin.X / Width;
        //    double globOrgPercY = this.Origin.Y / Height;

        //    return new Vector<int>(_imageList[imageIndex].RawWidth * globOrgPercX, _imageList[imageIndex].RawHeight * globOrgPercY);
        //    //_imageList[_currentImageIndex].Origin = newOrigin;
        //}

        //private void GoToNextImage()
        //{
        //    _currentImageIndex += 1;

        //    if (_currentImageIndex >= _imageList.Count)
        //    {
        //        if (WillLoop)
        //        {
        //            _currentImageIndex = 0;
        //        }
        //        else
        //        {
        //            _isRunning = false;
        //        }
        //    }
        //}
    }
}